#!/bin/bash

#WEB panel for BigLinux
#
#Authors:
#  Bruno Goncalves Araujo <www.biglinux.com.br>
#
#License: GPLv2 or later
#################################################



. /usr/share/bigcontrolcenter/default/theme-categories.sh

#Translation
export TEXTDOMAINDIR="/usr/share/locale-langpack"
export TEXTDOMAIN=bigcontrolcenter 

echo '
<script language="JavaScript">
window.resizeTo(640,480);
function NoResize(){
  window.resizeTo(640,480);
}
</script>
'



title=$"Configurar servidor WEB"
apply=$"Aplicar"
close=$"Sair"
back=$"Voltar para tela de configuracao"

#title
echo "<title>$title</title><body onResize=\"NoResize();\">"

#header
open_header
echo "$title" '</font><br>' $"Disponibilize informacao na WEB diretamente do seu computador."
close_header


#confere as variaveis que sao traduzidar com um p_ antes do nome

#Detecta se o apache esta instalado

if [ -e "/usr/sbin/apache2" ]
then
    if [ "$p_start_apache" = "yes" ]
    then
    echo "biglamp --start-apache" >> /tmp/biglamp$$
    else
    echo "biglamp --stop-apache" >> /tmp/biglamp$$
    fi

    if [ "$p_autostart_apache" = "yes" ]
    then
    echo "biglamp --autostart-apache" >> /tmp/biglamp$$
    else
    echo "biglamp --disable-autostart-apache" >> /tmp/biglamp$$
    fi

    if [ "$p_apache_port" != "$(grep ^Listen /etc/apache2/ports.conf | cut -d" " -f2)" ]
    then
    echo "biglamp --apache-port $p_apache_port" >> /tmp/biglamp$$
    fi
fi

if [ -e "/usr/bin/mysqld_safe" ]
then
    if [ "$p_start_mysql" = "yes" ]
    then
    echo "biglamp --start-mysql" >> /tmp/biglamp$$
    else
    echo "biglamp --stop-mysql" >> /tmp/biglamp$$
    fi

    if [ "$p_autostart_mysql" = "yes" ]
    then
    echo "biglamp --autostart-mysql" >> /tmp/biglamp$$
    else
    echo "biglamp --disable-autostart-mysql" >> /tmp/biglamp$$
    fi

    if [ "$p_pass_mysql" = "yes" ]
    then
    echo "biglamp --mysql-root-pass" >> /tmp/biglamp$$
    fi
fi

if [ "$p_remove_apache" = "yes" ]
then
echo "biglamp --remove-apache" >> /tmp/biglamp$$
fi

if [ "$p_install_apache" = "yes" ]
then
echo "biglamp --install-apache" >> /tmp/biglamp$$
fi

if [ "$p_remove_mysql" = "yes" ]
then
echo "biglamp --remove-mysql" >> /tmp/biglamp$$
fi

if [ "$p_install_mysql" = "yes" ]
then
echo "biglamp --install-mysql" >> /tmp/biglamp$$
fi

if [ "$p_install_php" = "yes" ]
then
echo "biglamp --install-php" >> /tmp/biglamp$$
fi

if [ "$p_remove_php" = "yes" ]
then
echo "biglamp --remove-php" >> /tmp/biglamp$$
fi



#Como as operacoes desse script precisam de permissao de root, todos os comandos foram salvos em um arquivo temporario utilizando o redirecionamento >>
#Lembre da importancia de incluir o $$ ao final de arquivos temporarios
#O chmod +x torna o aruqivo gerado executavel
chmod +x /tmp/biglamp$$

#A execucao propriamente dita utilizando obigsudo para dar permissao de root
bigsudo /tmp/biglamp$$ > /dev/null

#A remocao do arquivo temporario
rm -f /tmp/biglamp$$

#Exibir resposta para o usuario
echo "<br><br><br><br><br><center><font size=+2>"
echo $"Configuracao aplicada."
echo "</font></div><div id=\"rodape\"><button type=button  onClick=\"parent.location='apache.sh'\">   <img src=\"/usr/share/bigcontrolcenter/default/images/ok.png\" style=\"vertical-align:top\" />  $back   </button> 

<button type=button onClick= parent.location='/usr/share/bigbashview/exemplo2.sh?close=True'>   <img src=\"/usr/share/bigcontrolcenter/default/images/cancel.png\" style=\"vertical-align:top\"  />  $close     </button></form></div></body>"
